import axios from "axios";
import { useUserStore } from "@/store/model/user";
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: 9999999999999,
});
// http request 拦截器
service.interceptors.request.use(
  (config) => {
    const userStore = useUserStore();
    const token = userStore.getToken();
    const header: any = {
      "Content-Type": "application/json",
      ...config.headers,
    };
    if (token) {
      header["Authorization"] = "Bearer " + token;
      config.headers = header;
    }
    return config;
  },
  (error) => {
    return error;
  }
);


// http response 拦截器
service.interceptors.response.use(
  (response) => {
    //根据response-type 返回数据流
    if (response.headers["content-disposition"]) {
      return response;
    } else {
      return response.data;
    }
  },
  (error) => Promise.reject(error)
);
export default service;
